﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TRACv2.Domain.DTO;
//Author: Morgan William Davis III
//Project: TRAC Ticket Manager v2
//Date: 14 Mar 2014
using TRACv2.UI.Facade;

namespace TRACv2.UI
{
    public partial class FormEmployeeList : Form
    {
        private readonly TRACFacade _controller;

        public string ReturnEmployee;
        public EmployeeDTO EmployeeObject;

        public FormEmployeeList(TRACFacade controller)
        {
            InitializeComponent();
            _controller = controller;
            PopulateComboBox();

        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (cmbEmployeeList.Text != null)
            {
                EmployeeObject = cmbEmployeeList.SelectedItem as EmployeeDTO;
                ReturnEmployee = cmbEmployeeList.Text;
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                this.DialogResult = DialogResult.Cancel;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void PopulateComboBox()
        {
            var empList = _controller.GetAllEmployees();
            foreach (var i in empList)
            {
                cmbEmployeeList.Items.Add(i);
            }
        }

        private void FormEmployeeList_Load(object sender, EventArgs e)
        {

        }

        private void btnFilter_Click(object sender, EventArgs e)
        {
            var empList = _controller.FilterEmployeeList(txtFilter.Text);
            cmbEmployeeList.Items.Clear();
            foreach (var i in empList)
            {
                cmbEmployeeList.Items.Add(i);
            }
        }
    }
}
